package library.operation;

import library.Book;
import library.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        //用户来指定删除那本书
        //可以按照书名、序号来删除
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要删除的书的序号：");
        int index=scanner.nextInt();
        if(index<1 || index>bookList.getSize()){
            System.out.println("输入的序号超出范围！");
            return ;
        }
        //判定删除的书下标是不是最后一个
        if(index==bookList.getSize()-1){
            bookList.setSize(bookList.getSize()-1);
            return ;
        }else{
            //将最后一本书复制到要删除的书的位置
            Book lastBook=bookList.getBook(bookList.getSize()-1);
            //然后size减1
            bookList.setSize(bookList.getSize()-1);
        }
        System.out.println("删除书籍成功！");


    }
}
